import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:playtruly/common/routers/names.dart';
import 'package:playtruly/common/routers/observer.dart';
import 'package:playtruly/pages/index.dart';
import '../../pages/my/my_index/page/activity_application_management_page.dart';
import '../../pages/my/my_index/page/activity_application_management_bindings.dart';

class RoutePages {
  // 路由观察者
  static final AppRouteObserver observer = AppRouteObserver();

  // 路由历史
  static final List<String> history = <String>[];

  // 历史记录最大长度
  static const int maxHistoryLength = 20;

  // 添加路由历史记录
  static void addHistory(String? route) {
    if (route != null && route.isNotEmpty) {
      // 如果是重复的最后一个路由，不添加
      if (history.isNotEmpty && history.last == route) {
        return;
      }

      // 添加新路由
      history.add(route);

      // 如果超出最大长度，移除最早的记录
      if (history.length > maxHistoryLength) {
        history.removeAt(0);
      }

      debugPrint('路由历史 [${history.length}/$maxHistoryLength]: $history');
    }
  }

  // 获取上一个路由
  static String? get previousRoute {
    if (history.length < 2) return null;
    return history[history.length - 2];
  }

  // 获取当前路由
  static String? get currentRoute {
    if (history.isEmpty) return null;
    return history.last;
  }

  // 清除历史
  static void clearHistory() {
    history.clear();
    debugPrint('路由历史已清空');
  }

  // 列表
  static List<GetPage> list = [
    GetPage(
      name: RouteNames.home,
      page: () => const HomePage(),
      binding: HomeBinding(),
    ),
    GetPage(
      name: RouteNames.messageMessageDetial,
      page: () => const MessageDetialPage(),
      binding: MessageDetialBinding(),
    ),
    GetPage(
      name: RouteNames.messageMessageIndex,
      page: () => const MessageIndexPage(),
    ),
    GetPage(
      name: RouteNames.myMyIndex,
      page: () => const MyIndexPage(),
      binding: MyIndexBinding(),
    ),
    GetPage(
      name: RouteNames.myPeofileDetial,
      page: () => const PeofileDetialPage(),
    ),
    GetPage(name: RouteNames.myFunds, page: () => const FundsPage()),
    GetPage(name: RouteNames.myLevel, page: () => const LevelPage()),
    GetPage(name: RouteNames.myRecharge, page: () => const RechargePage()),
    GetPage(name: RouteNames.mySecurity, page: () => const SecurityPage()),
    GetPage(name: RouteNames.mySetting, page: () => const SettingPage()),
    GetPage(name: RouteNames.mySupport, page: () => const SupportPage()),
    GetPage(
      name: RouteNames.myUserHistoryActivite,
      page: () => const UserHistoryActivitePage(),
    ),
    GetPage(
      name: RouteNames.systemLogin,
      page: () => const LoginPage(),
      binding: LoginBinding(),
    ),
    GetPage(
      name: RouteNames.systemMain,
      page: () => const MainPage(),
      binding: MainBinding(),
    ),
    GetPage(
      name: RouteNames.systemRegist,
      page: () => const RegistPage(),
      binding: RegistBinding(),
    ),

    GetPage(
      name: RouteNames.systemSplash,
      page: () => const SplashPage(),
      binding: SplashBinding(),
    ),
    GetPage(
      name: RouteNames.systemAgreementPrivacyPolicy,
      page: () => const AgreementPrivacyPolicyPage(),
      binding: AgreementPrivacyPolicyBinding(),
    ),

    GetPage(
      name: RouteNames.playMyPublish,
      page: () => const MyPublishPage(),
      binding: MyPublishBinding(),
    ),
    GetPage(
      name: RouteNames.playPlayIndex,
      page: () => const PlayIndexPage(),
      binding: PlayIndexBinding(),
    ),

    GetPage(
      name: RouteNames.playPlayTogether,
      page: () => const PlayTogetherPage(),
      binding: PlayTogetherBinding(),
    ),
    GetPage(
      name: RouteNames.playReview,
      page: () => const ReviewPage(),
      binding: ReviewBinding(),
    ),
    GetPage(
      name: RouteNames.playActivte,
      page: () => const ActivtePage(),
      binding: ActivteBinding(),
    ),
    GetPage(name: RouteNames.playai, page: () => const PlayaiPage()),

    GetPage(
      name: RouteNames.postPostComment,
      page: () => const PostCommentPage(),
    ),
    GetPage(name: RouteNames.postPostEvent, page: () => const PostEventPage()),
    GetPage(name: RouteNames.playPlays, page: () => const PlaysPage()),
    GetPage(name: RouteNames.systemMap, page: () => const MapPage()),
          GetPage(
        name: RouteNames.messageMessageChat,
        page: () => const MessageChatPage(),
      ),
            GetPage(
        name: RouteNames.myUserInfo,
        page: () => const UserInfoPage(),
      ),
      GetPage(
        name: '/activity_application_management',
        page: () => const ActivityApplicationManagementPage(),
        binding: ActivityApplicationManagementBindings(),
      ),
  ];
} 
